//
//  TQTypeVc.swift
//  GjCup
//
//  Created by abc on 2024/4/12.
//

import UIKit

class TQTypeVc: UIViewController {
    
    @IBOutlet weak var cColView: UICollectionView!
    
    let types = ["爱情","道德","青春","愿望","集体","理想","志向","人才","谦虚","人格","天才","青年","社会","国家","财富","智慧","修养","工作","妇女","儿童","思想","理智","学习","科学","信仰","诚信","读书","成败","奉献","劳动","节约","教育","企业","事业","时间","勤奋","民族","真理","友谊","自由","心理","心灵","人生","幸福","团结","民族","真理","友谊","自由","心理","心灵","人生","幸福","团结"]
    var block:((String, Int)->())?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    
    }
   
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
extension TQTypeVc: UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return types.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TQTypeCell", for: indexPath) as! TQTypeCell
        cell.tLa.text = types[indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        block?(types[indexPath.item], indexPath.item + 1)
        navigationController?.popViewController(animated: true)
        
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 10
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 10
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let sw = UIScreen.main.bounds.width
        let itemw = (sw - 50) / 4
        
        return CGSize(width: itemw, height: 40)
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 20, left: 10, bottom: 0, right: 10)
    }
    
    
}
